package com.jackrain.nea.omslocal.util;

import com.alibaba.fastjson.JSONArray;
import com.aliyun.openservices.ons.api.Action;
import com.aliyun.openservices.ons.api.ConsumeContext;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.MessageListener;
import com.aliyun.openservices.ons.api.impl.util.MsgConvertUtil;
import com.jackrain.nea.config.PropertiesConf;
import com.jackrain.nea.omslocal.Dao.TaoBaoFullQtyDao;
import com.jackrain.nea.omslocal.Dao.VopFullQtyDao;
import com.jackrain.nea.omslocal.service.SendMqServies;
import com.jackrain.nea.util.ApplicationContextHandle;
import lombok.extern.slf4j.Slf4j;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * @Discription:
 *  唯品会全量库存同步消息 listener
 * Created with IntelliJ IDEA.
 * @Author xyc
 */
@Slf4j
public class FullQtyVopMsgListener implements MessageListener {


    @Override
    public Action consume(Message message, ConsumeContext consumeContext) {
        VopFullQtyDao vopFullQtyDao = ApplicationContextHandle.getBean(VopFullQtyDao.class);
        try {
            //唯品会全量库存同步
            JSONArray fullQtyArr = JSONArray.parseArray(MsgConvertUtil.objectDeserialize(message.getBody()).toString());
            vopFullQtyDao.fullQtyStart(fullQtyArr, message.getKey(), message.getTopic(), message.getTag());
//            log.debug(message.getTopic()+ "===" +message.getTag()+" === "+message.getKey());
        } catch (Exception e) {
            log.error("消费报错msgkey=>"+ message.getKey() + " topic=>"+ message.getTopic());
            // 出现异常
            return Action.CommitMessage;
        }

        return Action.CommitMessage;
    }





}
